package es.aa.android.cartomatic.appview.listener;

import android.view.DragEvent;
import android.view.View;
import android.view.View.OnDragListener;
import android.view.ViewGroup;
import es.aa.android.cartomatic.customview.CardView;

public class DragListener implements OnDragListener {

	private ViewGroup layout;
	
	public DragListener(ViewGroup layout) {
		this.layout = layout;
	}
	
	@Override
	public boolean onDrag(View v, DragEvent event) {
		View view = (View) event.getLocalState();
		ViewGroup owner = (ViewGroup) view.getParent();
		int action = event.getAction();
		
		switch (action) {
		case DragEvent.ACTION_DRAG_STARTED:
			break;
			
		case DragEvent.ACTION_DRAG_ENTERED:
			break;
			
		case DragEvent.ACTION_DRAG_EXITED:
			break;
			
		case DragEvent.ACTION_DROP:
			owner.removeView(view);
			
			if (layout instanceof CardView) {
				layout.addView(view);
			} else {
				layout.addView(view, 0);
			}
			
			view.setAlpha(1);
			view.setVisibility(View.VISIBLE);
			break;
			
		case DragEvent.ACTION_DRAG_ENDED:
			
			break;
			
		default:
			break;
		}
		return true;
	}
	
}
